package com.sunny.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.sunny.model.JxCount;
import com.sunny.service.IJxService;

import testcase.JxInfo;

@Service
public class Jxserivce implements IJxService {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public void setJdbcT(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	public List<JxInfo> findALL() {
		String sql = "select * from test_info";
		List<JxInfo> queryForList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(JxInfo.class));

		return queryForList;
	}

	public void insertJxCount(JxCount jc) {
		String sql = "insert into jxcount( name , per, perCaption , datetime , caption) values (?,?,?,?,?)";
		jdbcTemplate.update(sql, jc.getName(), jc.getPer(), jc.getPerCaption(), jc.getDatetime(), jc.getCaption());

	}
 	public void batchJnsertJxCount(List<JxCount> list) {
		String sql = "insert into jxcount( name , per, perCaption , datetime , caption) values (?,?,?,?,?)";
		List<Object[]> ss = new ArrayList<>();
		for (JxCount jc : list) {
			Object[] ob = {jc.getName(), jc.getPer(), jc.getPerCaption(), jc.getDatetime(), jc.getCaption()};
			ss.add(ob);
		}
		jdbcTemplate.batchUpdate(sql, ss);
		
	}

}
